package com.wzy.gmall.publisher.controller;

import com.wzy.gmall.publisher.bean.NameValue;
import com.wzy.gmall.publisher.service.PublisherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/*控制层*/
@RestController
public class PublisherController {
    @Autowired
    PublisherService publisherService;

    /*日活分析*/
    @GetMapping("dauRealtime")
    public Map<String, Object> dauRealtime(@RequestParam("td") String td) {
        Map<String, Object> results = publisherService.doDauRealtime(td);
        return results;
    }

    /*交易分析-按照年龄、类别统计
     * http://bigdata.gmall.com/statsByItem?itemName=小米手机&date=2021-02-02&t=gender*/
    @GetMapping("statsByItem")
    public List<NameValue> statsByItem(
            @RequestParam("itemName") String itemName,
            @RequestParam("date") String date,
            @RequestParam("t") String t) {
        List<NameValue> results = publisherService.doStatsByItem(itemName, date, t);
        return results;
    }

    /**
     * 交易分析：明细数据
     * http://bigdata.gmall.com/detailByItem?date=2023-01-06&itemName=小米手机&pageNo=18&pagesize=20
     */
    @GetMapping("detailByItem")
    public Map<String, Object> detailByItem(
            @RequestParam(value = "date",defaultValue = "2023-01-07") String data,
            @RequestParam(value = "itemName",defaultValue = "小米手机") String itemName,
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize
    ) {
        Map<String, Object> results = publisherService.doDetailByItem(data, itemName, pageNo, pageSize);
        return results;
    }


}
